package com.axc.base.dao;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.StatementType;

public interface GeneratorMapper {

//	@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables"
//			+ " where table_schema = (select database())")
//	List<Map<String, Object>> list();
//
//	@Select("select count(*) from information_schema.tables where table_schema = (select database())")
//	int count(Map<String, Object> map);
//
//	@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables \r\n"
//			+ "	where table_schema = (select database()) and table_name = #{tableName}")
//	Map<String, String> get(String tableName);
//
//	@Select("select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
//			+ " where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position")
//	List<Map<String, String>> listColumns(String tableName);

	@Select("select t.table_name  tableName,t.tablespace_name  engine,NVL(d.comments,'') tableComment,t.LAST_ANALYZED createTime"
			+ " from user_tables t left join user_tab_comments d on t.TABLE_NAME=d.table_name and d.table_type='TABLE'")
	List<Map<String, Object>> list();

	//select t.table_name  tableName,t.tablespace_name  engine,NVL(d.comments,'') tableComment,t.LAST_ANALYZED createTime
	//from user_tables t left join user_tab_comments d on t.TABLE_NAME=d.table_name and d.table_type='TABLE'

	@Select("select count(*)"
			+ " from user_tables t left join user_tab_comments d on t.TABLE_NAME=d.table_name and d.table_type='TABLE'")
	int count(Map<String, Object> map);

	@Select("select t.table_name  tableName,t.tablespace_name  engine,NVL(d.comments,'') tableComment,t.LAST_ANALYZED createTime"
			+ " from user_tables t left join user_tab_comments d on t.TABLE_NAME=d.table_name and d.table_type='TABLE'	where t.table_name = #{tableName}")
	Map<String, String> get(String tableName);

	//	@Select("select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
//			+ " where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position")
	@Select("select c.table_name,c.column_name columnName,t.DATA_TYPE dataType,c.comments columnComment,t.DATA_LENGTH dataLenth,t.DATA_SCALE dataScale,(case when col.column_name=c.column_name then 'P' else '' end) columnKey,'seq' extra"
			+ " from user_col_comments c inner join User_Tab_Columns t on c.Table_Name=t.Table_Name and c.column_name=t.column_name"
			+ " left join user_constraints au on c.table_name=au.table_name and au.constraint_type = 'P'"
			+ " left join user_cons_columns col on au.constraint_name=col.constraint_name"
			+ " where c.Table_Name=#{tableName} order by t.COLUMN_ID")
	List<Map<String, String>> listColumns(String tableName);


	@Select("select ${seqName}.Nextval from dual")
	@Options(statementType=StatementType.STATEMENT)
	Long getSeqNext(@Param("seqName")String seqName);

}
